<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Unix Domain Socket支持</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.connecting.mongos.html">Sharding</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.connecting.pools.html">Connection Pooling (version 1.2.0-1.2.12 *only*)</a></div>
 <div class="up"><a href="mongo.connecting.html">链接服务器</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongo.connecting.uds" class="section">
  <h2 class="title">Unix Domain Socket支持</h2>

  <p class="para">
   MongoDB 服务程序内置支持通过 Unix Sockets 链接，并且会在启动时建立socket，默认位置在
   <var class="filename">/tmp/mongodb-&lt;port&gt;.sock.</var>.
  </p>

  <p class="para">
   要通过socket链接，需要在连接字符串中指定socket路径，如：
  </p>

  <div class="example" id="mongo.connecting.uds-example">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb:///tmp/mongo-27017.sock"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

  <p class="para">
   如果要在通过socket的链接中对数据库进行认证（如上文所述），你需要指定一个端口号
   <em>0</em> 让链接字符串解析时可以找到 socket路径 的结尾。另外，你可以在链接的时候使用options参数。
  </p>

   <div class="example" id="mongo.connecting.uds-auth-example">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://username:password@/tmp/mongo-27017.sock:0/foo"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

  <div class="simplesect">
   <h3 class="title">更新日志</h3>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.0.9</td>
       <td>
        添加 Unix Sockets 的支持。
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>

 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.connecting.mongos.html">Sharding</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.connecting.pools.html">Connection Pooling (version 1.2.0-1.2.12 *only*)</a></div>
 <div class="up"><a href="mongo.connecting.html">链接服务器</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
